import util from "../../util";
export default class eventModelCollection {
    constructor() {
        this.util=util;
        this.info=[];
        this.infoTree=[];
        this.infoCascader=[];
        this.list=[];
        this.listTree=[];
        this.listCascader=[];
        this.records=[];
        this.recordsTree=[];
        this.recordsCascader=[];
        this.total=0;
    }
    static create(){
        let object=new eventModelCollection();
        return object;
    }
    async listAll(){
        let result = await util.api.Event.queryIncludeUnpublished({}).then(data=>{
            if(!!data) {
                this.list = data;
                this.listTree = util.getTree(data, 'category', 'name')
                this.listCascader = util.getCascader(data, 'category', 'name')
                return true;
            }else{
                return false;
            }
        }).catch(err=>{
            return false;
        });
        return result;
    }
    async listAllInfo(){
        let result = await util.api.Event.queryInfoIncludeUnpublished({}).then(data=>{
            if(!!data) {
                this.info = data;
                this.infoTree = util.getTree(data, 'category', 'name');
                this.infoCascader = util.getCascader(data, 'category', 'name');
                return true;
            }else{
                return false;
            }
        }).catch(err=>{
            return false;
        });
        return result;
    }
    async queryByPage(pageNumber, pageSize,filter){
        let result = await util.api.Event.queryByPage(pageNumber, pageSize, {condition:filter}).then(data=>{
            if(!!data) {
                this.records = data.records;
                this.total = data.recordCount;
                this.recordsTree = util.getTree(data.records, 'category', 'name')
                this.recordsCascader = util.getCascader(data.records, 'category', 'name')
                return true;
            }else{
                return false;
            }
        }).catch(err=>{
            return false;
        });
        return result;
    }
}